﻿using BaseDal;
using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseBll
{
    public class SupplierBll
    {
        static readonly Lazy<SupplierBll> dal = new Lazy<SupplierBll>(() => new SupplierBll());
        public static SupplierBll Instance { get; } = dal.Value;
        private SupplierBll() { }

        /// <summary>
        /// 查询数据是否存在
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public bool IsExist(string strWhere)
        {
            return SupplierDal.Instance.IsExist(strWhere);
        }

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetPageList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return SupplierDal.Instance.GetPageList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public List<Supplier> GetList(string strWhere)
        {
            return SupplierDal.Instance.GetList(strWhere);
        }

        /// <summary>
        /// 根据id查询实体类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Supplier GetModelById(int id)
        {
            return SupplierDal.Instance.GetModelById(id);
        }

        /// <summary>
        /// 新增供应商
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddSupplier(Supplier model)
        {
            return SupplierDal.Instance.AddSupplier(model);
        }

        /// <summary>
        /// 修改物品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateSupplier(Supplier model)
        {
            return SupplierDal.Instance.UpdateSupplier(model);
        }

        /// <summary>
        /// 删除物品
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool DeleteSupplier(string ids)
        {
            return SupplierDal.Instance.DeleteSupplier(ids);
        }

        /// <summary>
        /// 验证model各字段合法性
        /// </summary>
        /// <param name="model"></param>
        /// <param name="msg">错误信息</param>
        /// <returns></returns>
        public bool VerifyModel(Supplier model, ref string msg)
        {

            if (string.IsNullOrEmpty(model.S_Name))
            {
                msg = "供应商名称不能为空";
                return false;
            }

            return true;
        }

    }
}
